/*
	Copyright (c) 2010 <copyright holders>
	This source code is licensed under The MIT License,
	see the file LICENSE for details.
	*/

#ifndef CLIENT_HPP
#define CLIENT_HPP

#include "Connection.hpp"
#include "Net.hpp"

namespace spelprog2 {
namespace net {

class Client : public Net {
    HIDE_EVIL_CONSTRUCTORS(Client);

    Connection::Pointer peer_;
    MessageListenerRegistry<NetMessageInfo> internalRegistry_;
    UserId myUserId_;

    void connect(const std::string & host, unsigned port, const std::string & password, const std::string & username);

public:
    Client(const std::string & host, unsigned port, const std::string & password, const std::string & username);
    ~Client();

    void setUserId(UserId id);
    void disconnect() { peer_->getSocket().close(); }

    // Implementations of super methods =======================================

    virtual UserId getMyClientId() const;

    virtual void sendToUser(const spelprog2::Message & msg, UserId dest);
    virtual void sendToAll(const spelprog2::Message & msg);
};

}; //namespace net
}; //namespace spelprog2

#endif //CLIENT_HPP
